package com.wolves.career.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wolves.career.entity.ProCategory;
import com.wolves.career.entity.ProSchoolCategory;
import com.wolves.career.mapper.ProCategoryMapper;
import com.wolves.career.service.ProCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wolves.career.service.ProSchoolCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 门类（专业大类） 服务实现类
 * </p>
 *
 * @author 麦翔盛
 * @since 2021-10-31
 */
@Service
public class ProCategoryServiceImpl extends ServiceImpl<ProCategoryMapper, ProCategory> implements ProCategoryService {

    @Autowired
    private ProSchoolCategoryService schoolCategoryService;

    @Override
    public List<ProCategory> getCategoryBySchoolId(String schoolId) {
        //根据中间表获取所有学校id
        QueryWrapper<ProSchoolCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("school_id", schoolId);
        List<ProSchoolCategory> list = schoolCategoryService.list(queryWrapper);

        List<ProCategory> finalList = new ArrayList<>();

        for (ProSchoolCategory proSchoolCategory : list) {
            String categoryId = proSchoolCategory.getCategoryId();
            ProCategory proCategory = baseMapper.selectById(categoryId);
            if (proCategory != null) {
                finalList.add(proCategory);
            }
        }

        return finalList;
    }
}
